package com.zzl.admin.dao.admin;

import com.zzl.admin.dao.base.BaseDao;
import com.zzl.admin.entity.admin.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Description：资源DAO
 * Created by 朱正磊 on 2019-03-22 17:52
 */
public interface ResourceDao extends BaseDao<Resource, Integer> {

    /**
     * description：根据资源ID删除角色资源关联表里的数据
     * user 朱正磊
     * time 2019-03-25 09:41
     * @param resourceId 资源ID
     */
    @Modifying
    @Query(nativeQuery = true, value = "delete from tb_role_resource where resource_id = :resourceId")
    void deleteGrand(@Param("resourceId") Integer resourceId);

    /**
     * description：根据资源名称模糊查询分页记录
     * user 朱正磊
     * time 2019-03-25 09:49
     * @param name 资源名称
     * @param pageable 分页请求对象
     * @return 返回分页对象
     */
    Page<Resource> findAllByNameContaining(String name, Pageable pageable);

    /**
     * description：根据父资源ID升序、资源ID升序、排序字段sort升序查询资源分页
     * user 朱正磊
     * time 2019-03-25 10:08
     * @return 返回分页对象
     */
    List<Resource> findAllByOrderByParentAscIdAscSortAsc();

}
